/**
 * 自动补全组件
 * */
layui.define(['autocomplete', 'globalConfig', 'sdLocal'], (exports) => {
	let autocomplete = layui.autocomplete;
	let globalConfig = layui.globalConfig;
	let sdLocal = layui.sdLocal;

	let sdAutocomplete = {
		render(param) {
			let cols = param.cols;
			let params = [];
			let type = param.type ? param.type : "sug"; //设置输入框提示类型：sug-下拉框，sugTable-下拉表格

			cols.forEach(x => {
				let p = {
					name: x.field,
					field: x.field
				}
				params.push(p);
			})
			let header = {
				"Content-Type": "application/json;charset=UTF-8",
				"token": (typeof sdLocal.token.get()) == 'undefined' ? '' : sdLocal.token.get()
			};

			autocomplete.render({
				id: param.id,
				cols: [
					cols
				], //设置表头
				params: params, //设置字段映射，适用于输入一个字段，回显多个字段
				type: type,
				headers: header,
				url: globalConfig.action + param.url,
				callback: param.callback
			})
		}
	}
	exports('sdAutocomplete', sdAutocomplete);


})
